<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>寄生思想</title>
</head>
<body>
    <script>
        function Person(name,age,height)
        {
            this.name = name;
            this.age = age;
            this.height = height;
        }

        Person.prototype.eat = function()
        {
            console.log("我在吃饭");
        }

        Person.prototype.sleep = function ()
        {
            console.log("我要睡觉了");
        }

        function Student(name,age,height,grades,id)
        {
            //先关联上属性
            Person.call(this,name,age,height);
            this.grades = grades;
            this.id = id;
        }

        // //第一种
        // var obj = {};
        // Object.setPrototypeOf(obj,Person.prototype);
        // Student.prototype = obj;
        // //创建student对象
        // var stu = new Student("cq",18,1.88,100,12345);
        // console.log(stu.name);
        // stu.eat();

        // //第二种
        // function fn(){};
        // fn.prototype = Person.prototype;
        // Student.prototype = new fn();
        // var stu = new Student("cq",18,1.88,100,12345);
        // console.log(stu.name);
        // stu.sleep();

        //第三种
        var obj = Object.create(Person.prototype);
        Student.prototype = obj;
        var stu = new Student("cq",18,1.88,100,12345);
        console.log(stu.name);
        stu.sleep();

    </script>
</body>
</html>